<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bind的小例子</title>
    <style>
        body {
            background-color: #344931;
        }
    </style>
</head>
<body>
    
</body>
<script>
    function Color(elem){
      this.colors = ['#27ae60', '#e74c3c', '#c0392b', '#3498db'];
      this.elem = elem;
      this.run = function(){
          setInterval(function(){
            let i = Math.floor(Math.random() * this.colors.length);
            this.elem.style.backgroundColor = this.colors[i];
          }.bind(this), 1000);
       }
    }

    let color = new Color(document.body);
    color.run();
</script>
</html>